package com.example.huadi1.controller;

import com.example.huadi1.mapper.SupplierMapper;
import com.example.huadi1.service.StudentGetBookService;
import com.example.huadi1.service.TeacherGetBookService;
import com.example.huadi1.utils.AjaxResult;
import com.example.huadi1.utils.Request.GetAllBook;
import com.example.huadi1.utils.Request.GetBookRequest;
import com.example.huadi1.utils.Request.QueryBookRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/GetBook")
@Slf4j
public class GetBookController {
    @Autowired
    StudentGetBookService studentGetBookService;
    @Autowired
    TeacherGetBookService teacherGetBookService;

    @Autowired
    private SupplierMapper supplierMapper;

    @PostMapping("/query")
    public AjaxResult query(@RequestBody QueryBookRequest queryBookRequest){
        AjaxResult res;
        if("student".equals(queryBookRequest.getRole())){
            res=studentGetBookService.queryStuBook(queryBookRequest);
        }
        else if("teacher".equals(queryBookRequest.getRole())){
            res=teacherGetBookService.queryBook(queryBookRequest);
        }
        else if("class".equals(queryBookRequest.getRole())){
            res=studentGetBookService.queryClassBook(queryBookRequest);
        }
        else res=AjaxResult.error();
        return res;
    }

    @PostMapping("/get")
    public AjaxResult get(@RequestBody GetBookRequest getBookRequest){
        AjaxResult res;
        if("student".equals(getBookRequest.getRole())){
            res=studentGetBookService.getStuBook(getBookRequest);
        }
        else if("teacher".equals(getBookRequest.getRole())){
            res=teacherGetBookService.getBook(getBookRequest);
        }
        else if("class".equals(getBookRequest.getRole())){
            res=studentGetBookService.getClassBook(getBookRequest);
        }
        else res=AjaxResult.error();
        return res;
    }

    @PostMapping("/getAll")
    public AjaxResult getAll(@RequestBody GetAllBook getAllBook){
        System.out.println(getAllBook.toString());
        AjaxResult res;
        if("student".equals(getAllBook.getRole())){
            res=studentGetBookService.getAllBook(getAllBook);
        }
        else if("teacher".equals(getAllBook.getRole())){
            res=teacherGetBookService.getAllTeacherBook(getAllBook);
        }
        else if("class".equals(getAllBook.getRole())){
            res=studentGetBookService.getAllClassBook(getAllBook);
        }
        else res=AjaxResult.error();
        return null;
    }
}
